package org.wangliang181230.leetcode.problems.p_1;

import java.util.HashMap;

/**
 * @author wangliang181230
 */
public class TwoSum_1 {

	public static int[] twoSum(int[] nums, int target) {
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(nums.length - 1);
		map.put(nums[0], 0);
		for (int i = 1; i < nums.length; i++) {
			int a = target - nums[i];
			if (map.containsKey(a)) {
				return new int[]{map.get(a), i};
			} else {
				map.put(nums[i], i);
			}
		}
		return null;
	}

}
